package cn.xjt.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 内容：
 *
 * @author
 * @date 2020/9/20-21:13
 */
public class HelloServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		//获取前端参数
		String method = req.getParameter("method");
		if(method.equals("add"))
		{
			req.getSession().setAttribute("msg", "执行了add方法");
		}
		else if(method.equals("delete"))
		{
			req.getSession().setAttribute("msg", "执行了delete方法");
		}
		else{
			req.getSession().setAttribute("msg", "没找到你的方法");
		}

		//调用业务层
		//视图转发或请求重定向
		System.out.println("开始跳转，测试页面");
		req.getRequestDispatcher("/WEB-INF/jsp/test.jsp").forward(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doGet(req,resp);
	}
}
